package com.nuc.service.impl;

import com.nuc.mapper.QueMapper;
import com.nuc.pojo.Question;
import com.nuc.pojo.Remark;
import com.nuc.service.QueService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author Zhang Chao
 * @Date 2021/5/12 10:58
 * @Version 1.0
 */
@Service
public class QueServiceImpl implements QueService {

    @Resource
    QueMapper queMapper;

    @Override
    public List<Question> getAllQue() {
        List<Question> allQue = queMapper.getAllQue();
        List<Question> allQue1 = new ArrayList<>();
        for(Question que: allQue){
           //System.out.println(que);
            ArrayList<Remark> remarks = new ArrayList<>();
            for(int i =1;i<=4;i++){
                Remark remark = new Remark();
                if(que.getAnswer()==i){
                    remark.setId(i);
                    remark.setName("正确答案");
                    remark.setUsname(false);
                    remarks.add(remark);
                    //System.out.println("正确"+remark);
                }else{
                    remark.setId(i);
                    remark.setName("错误答案");
                    remark.setUsname(false);
                    remarks.add(remark);
                    //System.out.println("错误"+remark);
                }
                //System.out.println("循环中的"+remarks);
            }
            //System.out.println(remarks);
            que.setArray(remarks);
            allQue1.add(que);
        }

        return allQue1;
    }
}
